/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.ejb;

import com.pos.domain.User;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author suraj
 */
@Stateless
public class UserEJB {

    @PersistenceContext
    private EntityManager em;

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void create(User user) {
        this.em.persist(user);
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void edit(User user) {
        this.em.merge(user);
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void delete(User user) {
        this.em.remove(user);
    }

    public List<User> findAll(){
        return this.em.createQuery("select u from User u ").getResultList();
    }
    public User findById(String loginId){
        return this.em.find(User.class, loginId);
    }
}
